//
//  NewsDetailHotReplyCell1.swift
//  甜言蜜语
//
//  Created by yingli_yanfa_liuxingyu on 16/8/25.
//  Copyright © 2016年 wl. All rights reserved.
//

import UIKit
protocol NewsDetailHotReplyDelegate {
    func NewsDetailHotReply(id: String)
}
class NewsDetailHotReplyCell1: UITableViewCell {
    var modelList: [NewsDetailHotReplyModel]?{
        didSet{
            
            self.tableView.reloadData()
        }
    }
    var delegate: NewsDetailHotReplyDelegate?
    
     @IBOutlet weak var tableView: UITableView!
    var type: String = ""
    override func awakeFromNib() {
        super.awakeFromNib()
        self.tableView.scrollEnabled = false
        publicMethod.hiddleExtendCellForTableView(self.tableView)
        
        let cellNib = UINib(nibName: "NewsDetailHotReplyFooterCell", bundle: nil)
        
        self.tableView.registerNib(cellNib, forCellReuseIdentifier: "NewsDetailHotReplyFooterCell")
        
    }
    func setCellContentWithCellInfo(cellInfo: [NewsDetailHotReplyModel]?) -> Void {
        self.modelList = cellInfo
        
    }
    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        
    }
    
    
    //MARK:tableviewDataSource
    func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
        if(cell.respondsToSelector(Selector("setSeparatorInset:"))) {
            cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0)
        }
        if(cell.respondsToSelector(Selector("setLayoutMargins:"))) {
            cell.layoutMargins = UIEdgeInsetsMake(0, 0, 0, 0)
        }
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if self.modelList?.count == nil{
            return 0
        }else{
            return (self.modelList?.count)!
        }
    }
    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        let font = UIFont(name: "Helvetica", size: 16)
        let height = publicMethod.getLabHeigh(self.modelList![indexPath.row].message, font: font!, width: SCREEN_WIDTH - 16)
        
        return 65 + height
        
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("NewsDetailHotReplyFooterCell") as! NewsDetailHotReplyFooterCell
        let cellInfo = self.modelList![indexPath.row]
        cell.modelList = cellInfo
        cell.delBtn.hidden = true
        cell.headType = "详情"
        return cell
        
    }
    
    
    // MARK: - Table view delegate
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        tableView.deselectRowAtIndexPath(indexPath, animated: true)
        if self.type == "回复"{
            delegate?.NewsDetailHotReply(self.modelList![indexPath.row].id)
        }
        if self.type == "活动"{
            delegate?.NewsDetailHotReply(self.modelList![indexPath.row].id)
        }
        
    }
    

    
}
